package de.dhbw.karlsruhe.picsim.model.decode;

import de.dhbw.karlsruhe.picsim.model.commands.PicInstruction;
import de.dhbw.karlsruhe.picsim.model.commands.impl.Call;
import de.dhbw.karlsruhe.picsim.model.commands.impl.GoTo;
import de.dhbw.karlsruhe.picsim.model.memory.OpCode;
import de.dhbw.karlsruhe.picsim.util.Bits;
import de.dhbw.karlsruhe.picsim.util.impl.BitUtilities;
import de.dhbw.karlsruhe.picsim.util.impl.Lengths;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jetbrains.annotations.NotNull;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: Apr 18, 2010
 * Time: 1:06:11 PM
 */
final class LiteralDecoder10 implements Decoder {
    private static final Log log = LogFactory.getLog(LiteralDecoder10.class);

    @NotNull
    @Override
    public PicInstruction decode(@NotNull final OpCode opCode) {
        log.debug("now decoding opcode" + opCode);
        final Bits bits = opCode.getValue();
        final Bits argument = BitUtilities.subBits(bits, 0, Lengths.CALL_GOTO_ARGUMENT_LENGTH);
        if (!bits.isSet(11)) {
            return new Call(argument);
        } else {
            return new GoTo(argument);
        }

    }
}
